using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace SqlTools.CodeGenerator.Data
{
	public class PrimaryKeyTableProperty : TableProperty
	{
		protected TablePropertyCollection _properties;

		public PrimaryKeyTableProperty(string name, Table table, string columnName)
			: base ( name, table, columnName)
		{
			_properties = new TablePropertyCollection(table);
		}

		public override TablePropertyType Type
		{
			get { return TablePropertyType.PrimaryKey; }
		}

		public TablePropertyCollection Properties
		{
			get { return _properties; }
		}

		public override void SaveXml(XmlDocument doc, XmlElement parent)
		{
			XmlElement el = CreateXmlElement(doc);
			parent.AppendChild(el);

			XmlElement xmlProperties = doc.CreateElement("Properties");
			el.AppendChild(xmlProperties);

			foreach ( TableProperty prop in _properties )
			{
				prop.SaveXml(doc, xmlProperties);
			}

		}

		public override void LoadXml(XmlElement xmlProp)
		{
			base.LoadXml(xmlProp);

			XmlNodeList nodes = xmlProp.GetElementsByTagName("Properties");
			if ( nodes.Count > 0 )
			{
				_properties.LoadXml(nodes[0] as XmlElement);
			}
		}
	}
}
